package com.example.artgallery.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage

@Composable
fun AddArtworkScreen(
    onBack: () -> Unit,
    onAddArtwork: () -> Unit,
    selectedImageUri: Uri?,
    onImageSelected: (Uri?) -> Unit,
    onSubmit: (String, String) -> Unit
) {
    var title by remember { mutableStateOf("") }
    var folder by remember { mutableStateOf("") }
    
    Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
        Button(onClick = onBack) {
            Text("返回")
        }
        
        Button(onClick = onAddArtwork) {
            Text("选择图片")
        }
        
        selectedImageUri?.let { uri ->
            AsyncImage(
                model = uri,
                contentDescription = "Selected image",
                contentScale = ContentScale.Fit,
                modifier = Modifier.weight(1f)
            )
        }
        
        OutlinedTextField(
            value = title,
            onValueChange = { title = it },
            label = { Text("作品标题") },
            modifier = Modifier.padding(8.dp)
        )
        
        OutlinedTextField(
            value = folder,
            onValueChange = { folder = it },
            label = { Text("文件夹名称") },
            modifier = Modifier.padding(8.dp)
        )
        
        Button(
            onClick = { onSubmit(title, folder) },
            enabled = selectedImageUri != null && title.isNotBlank() && folder.isNotBlank()
        ) {
            Text("添加作品")
        }
    }
}